package com.wtb.javatool.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wtb.javatool.common.PageResult;
import com.wtb.javatool.dao.LogMapper;
import com.wtb.javatool.vo.LogPageDto;
import com.wtb.javatool.entity.LogPage;
import com.wtb.javatool.service.ILogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

@Service
public class LogService implements ILogService {

    @Autowired
    private LogMapper logMapper;
    /**
     * 日志分页查询
     * @param logPageDTO
     * @return
     * */
    public PageResult pageQuery(LogPageDto logPageDTO) {
        String name = logPageDTO.getName();
        LocalDate startDate = logPageDTO.getStartDate();
        LocalDateTime startDateTime = LocalDateTime.of(startDate, LocalTime.MIN);
        LocalDate endDate = logPageDTO.getEndDate();
        LocalDateTime endDateTime = LocalDateTime.of(endDate, LocalTime.MAX);
        Integer pageNum = logPageDTO.getPageNum();
        Integer pageSize = logPageDTO.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        Page<LogPage> page = logMapper.pageQuery(name,  startDateTime, endDateTime);
        long total = page.getTotal();
        List<LogPage> result = page.getResult();
        return new PageResult(total, result);
    }
}
